package com.ohs.fo.action;

import java.util.List;
import java.util.Map;
import java.util.Set;

import com.ohs.bll.service.VideoService;
import com.ohs.dal.model.Tag;
import com.ohs.dal.model.Video;

public class VideoAction extends AbstractAction {
	private static final String VIDEO_LIST = "video list";
	private static final int TOP_SIZE = 20;
	private VideoService service;
	private Map<String, List<Video>> videos;
	private List<Video> refVideos;
	private String id;
	private Video video;

	public String show() throws Exception {
		videos = service.loadTopVideos(TOP_SIZE);
		return "success";
	}
	
	public String play() throws Exception {
		if (id != null && !"".equals(id)) {
			video = service.get(new Long(id));
			Set<Tag> tags = video.getTags();
			if (tags != null && tags.size() > 0) {
				refVideos = service.findRefVideos(tags.iterator().next().getId(), video.getId());
			}
		}
		return "success";
	}

	public Video getVideo() {
		return video;
	}

	public void setVideo(Video video) {
		this.video = video;
	}

	public VideoService getService() {
		return service;
	}

	public void setService(VideoService service) {
		this.service = service;
	}

	public Map<String, List<Video>> getVideos() {
		return videos;
	}

	public List<Video> getRefVideos() {
		return refVideos;
	}

	public void setRefVideos(List<Video> refVideos) {
		this.refVideos = refVideos;
	}

	public void setVideos(Map<String, List<Video>> videos) {
		this.videos = videos;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
	
}
